package com.spa.infrastructure.repository.service;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spa.infrastructure.repository.mapper.OrderAddressMapper;
import com.spa.infrastructure.repository.po.OrderAddressPO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class OrderAddressRepositoryService extends ServiceImpl<OrderAddressMapper, OrderAddressPO> {

    public boolean insertOrder(OrderAddressPO infoPO) {
        return save(infoPO);
    }
    public OrderAddressPO infoByOrderId(Long orderId) {
        LambdaQueryWrapper<OrderAddressPO> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(OrderAddressPO::getOrderId,orderId);
        List<OrderAddressPO> listPo = list(wrapper);
        if(CollUtil.isNotEmpty(listPo)) return listPo.get(0);
        return null;
    }

    public List<OrderAddressPO> listByOrderIds(List<Long> ids) {
        LambdaQueryWrapper<OrderAddressPO> wrapper = Wrappers.lambdaQuery();
        wrapper.in(OrderAddressPO::getOrderId,ids);
        List<OrderAddressPO> listPo = list(wrapper);
        return listPo;
    }

}
